package com.yinshan.androidlibsx

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.yinshan.androidlibsx.databinding.ActivityMainBinding
import com.yinshan.keyboard.KeyboardUtil
import com.yinshan.keyboard.YsKeyboardView
import com.yinshan.voiceplay.VoiceSpeaker
import com.yinshan.zxing.CameraScan
import com.yinshan.zxing.CaptureActivity
import java.lang.ref.WeakReference


class MainActivity : AppCompatActivity() {
    private lateinit var context: Context
    lateinit var binding: ActivityMainBinding

    private var keyboardUtil: KeyboardUtil? = null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        context = WeakReference(this).get()!!
        binding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)
        initViews()
    }

    private fun initViews() {
        keyboardUtil = KeyboardUtil(context as Activity?, binding.realMain)
        keyboardUtil?.initKeyboard(YsKeyboardView.KEYBOARDTYPE_NUM, binding.editNum)
        keyboardUtil?.initKeyboard(YsKeyboardView.KEYBOARDTYPE_ABC, binding.editAbc)
        keyboardUtil?.initKeyboard(YsKeyboardView.KEYBOARDTYPE_ID_NUM, binding.editIdNum)
        binding.btnHandle.setOnClickListener {

        }
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (requestCode == 100) {
            binding.txtContent.text = CameraScan.parseScanResult(data)
        }
    }
}